package com.waiter.moximoxi.presenter;

import android.content.Context;

import com.landicorp.android.eptapi.device.Printer;

import java.util.List;

import cn.yhong.aframework.utils.AtyUtils;

/**
 * Created by Czl on 2017/7/27.
 */

public class PrinterPresenterImpl implements IPrinterPresenter {

    private Context context;
    private PrinterImpl printer;

    public PrinterPresenterImpl(final Context context) {
        this.context = context;
        this.printer = new PrinterImpl(context) {
            @Override
            protected void onDeviceServiceCrash() {
                AtyUtils.i("打印数据", "device service crash");
            }

            @Override
            protected void displayInfo(String info) {
                AtyUtils.i("打印数据", info);
            }

            @Override
            protected void toast(String msg) {
                AtyUtils.showShort(context, msg, true);
            }
        };
        init();
    }

    public void init() {
        int ret = printer.getPrinterStatus();
        if (ret != Printer.ERROR_NONE) {
            AtyUtils.i("打印数据", printer.getDescribe(ret));
            return;
        }
        printer.init();
    }

    @Override
    public void start(List<Object> value) {
        printer.addText(value);
//        if (!printer.addBarcode()) {
//            view.displayInfo("add barcode fail");
//            return;
//        }
//        if (!printer.addQRcode()) {
//            view.displayInfo("add qrcode fail");
//            return;
//        }
//        if (!printer.feedLine(3)) {
//            view.displayInfo("feed line fail");
//            return;
//        }
//        if (!printer.cutPaper()) {
//            view.displayInfo("cut page fail");
//            return;
//        }
        printer.startPrint();
    }
}
